unit UChangeRes;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs,Jpeg, StdCtrls, ExtDlgs,math, ComCtrls;

type
  TForm1 = class(TForm)
    OPD: TOpenPictureDialog;
    Label1: TLabel;
    LFile: TLabel;
    Button1: TButton;
    Button2: TButton;
    PB: TProgressBar;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
var
i,Dw,Dh:integer;
BS:TJPEGImage;
BD:Tbitmap;
sx,sy,sn:real;
ARect:TRect;
stf:string;
begin
BD:=Tbitmap.Create;
BS:=TJPEGImage.Create;
  try
  if opd.Execute then
    begin
    PB.Max:=opd.Files.Count;
    PB.Position:=0;
    PB.Show;
    for i := 0 to opd.Files.Count-1 do
      if (UpperCase(extractfileext(opd.files[i]))='.JPG') or
         (UpperCase(extractfileext(opd.files[i]))='.JPEG') then
      begin
      LFile.Caption:=opd.files[i];
      bS.LoadFromFile(opd.files[i]); 
      application.ProcessMessages;
      sx:=bS.Width /640;
      sy:=bS.height /480;
      sn:=min(sx,sy);
      Dw:=round(BS.Width/sn);
      Dh:=round(BS.Height/sn);
      BD.Width:=Dw;
      BD.Height:=Dh;
      ARect := Rect(0,0, Dw, Dh);
      bD.Canvas.StretchDraw(ARect, bS); 
      application.ProcessMessages;
      BS.Assign(bd);
      stf:=Extractfilepath(opd.files[i])+'Z'+Extractfilename(opd.files[i]);
      bs.SaveToFile(stf);
      PB.Position:=PB.Position+1;
      application.ProcessMessages;
      end;
    end;
  finally
  BD.Free;
  BS.Free;
  end;
pb.Hide;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
close;
end;

end.
